package com.owc.service.app;

import com.owc.common.context.JwtTokenHelper;
import com.owc.common.enums.ClientEnum;
import com.owc.common.tool.DateUtils;
import com.owc.domain.dto.Authority;
import com.owc.domain.dto.PayPwd;
import com.owc.domain.dto.UserInfo;
import com.owc.domain.vo.app.LoginVo;
import com.owc.domain.vo.app.ModifyVo;
import com.owc.domain.vo.app.RegisterVo;
import com.owc.filter.content.UserDetail;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;

import java.util.Optional;

/**
 * @Author xiaom
 * @Date 2019/12/2 14:34
 * @Version 1.0.0
 * @Description <>
 **/
public interface PermissionService {
    /**
     * New user register interface.
     * @param registerVo Request register params.
     * @return flag
     */
    Authority register(@NonNull RegisterVo registerVo);

    /**
     * User login.
     * @return JWT token.
     */
    @NonNull
    Authority login(LoginVo loginVo);

    /**
     * Query current login user info.
     * @return {@link com.owc.domain.dto.UserInfo}
     */
    @NonNull
    UserInfo getUserInfo();

    /**
     * Account login. Use password the way.
     */
    String loginByPassword(LoginVo loginVo);

    /**
     * Account login.Use auth code the way.
     */
    String loginByAuthCode(LoginVo loginVo);

    /**
     * Get user info with the client type.
     * @param clientType {@link com.owc.common.enums.ClientEnum}
     */
    @NonNull
    Optional<UserDetail> getUserDetailByClient(@NonNull String userName, @NonNull Integer clientType);

    /**
     * Modify password. （Login password OR Pay password）
     */
    Boolean modifyPassword(ModifyVo modifyVo);

    /**
     * Check is set pay password.
     */
    PayPwd checkIsSetPayPwd();

    /**
     * Issue of JWT certificate
     * @param user User basis info model.
     * @return JWT token.
     */
    static String signatureJwtToken(UserDetail user){
        return JwtTokenHelper.generateToken(user, DateUtils.TIME_ONE_DAY * 7);
    }

}
